package service;

import dao.UserDao;
import domain.User;
import dto.UserDto;
import org.springframework.util.StringUtils;

/**
 * Created by zhifu on 2015/3/25.
 */
public class UserServiceImpl implements UserService {
    private UserDao userDao;

    @Override
    public void saveOrUpdate(UserDto userDto) {
        User user = userDto.toUser(userDao);
        userDao.saveOrUpdate(user);
    }

    @Override
    public UserDto loadByGuid(String guid) {
        if(StringUtils.hasText(guid)){
            User user = userDao.findUserByGuid(guid);
            return new UserDto(user);
        }else{
            return new UserDto();
        }
    }

    public void setUserDao(UserDao userDao) {
        this.userDao = userDao;
    }
}
